package o;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest.Builder;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class dno {
    private static final Object ˊ = new Object();
    private static dno ॱ;
    private boolean ʼ;
    private NetworkCallback ʽ;
    private final Map<Handler, Integer> ˋ = new HashMap();
    private Object ˎ = new byte[0];
    private Context ˏ = null;
    private e ᐝ;

    class a extends NetworkCallback {
        final /* synthetic */ dno ˏ;

        private a(dno o_dno) {
            this.ˏ = o_dno;
        }

        public void onAvailable(Network network) {
            super.onAvailable(network);
            this.ˏ.ˎ();
        }

        public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
            super.onCapabilitiesChanged(network, networkCapabilities);
            this.ˏ.ˎ();
        }

        public void onLost(Network network) {
            super.onLost(network);
            this.ˏ.ˎ();
        }
    }

    public enum c {
        ˎ(0),
        CONNECTED(1),
        NOT_CONNECTED(2);
        
        private int ॱ;

        private c(int i) {
            this.ॱ = 0;
            this.ॱ = i;
        }

        public static c ॱ(int i) {
            switch (i) {
                case 0:
                    return ˎ;
                case 1:
                    return CONNECTED;
                case 2:
                    return NOT_CONNECTED;
                default:
                    return ˎ;
            }
        }

        public int ˎ() {
            return this.ॱ;
        }
    }

    class e extends SafeBroadcastReceiver {
        final /* synthetic */ dno ˎ;

        private e(dno o_dno) {
            this.ˎ = o_dno;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null && context != null) {
                if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
                    this.ˎ.ˎ();
                }
            }
        }
    }

    public dno() {
        if (VERSION.SDK_INT >= 24) {
            this.ʽ = new a();
        } else {
            this.ᐝ = new e();
        }
    }

    public static dno ॱ() {
        dno o_dno;
        synchronized (ˊ) {
            if (ॱ == null) {
                ॱ = new dno();
            }
            o_dno = ॱ;
        }
        return o_dno;
    }

    public static boolean ॱ(int i) {
        if (i == 1) {
            return true;
        }
        return false;
    }

    public static NetworkInfo ˊ(Context context) {
        return ((ConnectivityManager) context.getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo();
    }

    private synchronized void ˎ() {
        if (this.ˏ != null) {
            c cVar;
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) this.ˏ.getApplicationContext().getSystemService("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
                cVar = c.NOT_CONNECTED;
            } else {
                cVar = c.CONNECTED;
            }
            Logger.ˏ("NetworkConnectivity", "onReceive(): " + activeNetworkInfo + ", mState=" + cVar);
            synchronized (this.ˎ) {
                for (Entry entry : this.ˋ.entrySet()) {
                    Handler handler = (Handler) entry.getKey();
                    Integer num = (Integer) entry.getValue();
                    if (!(handler == null || num == null)) {
                        Message obtain = Message.obtain(handler, num.intValue());
                        obtain.obj = activeNetworkInfo;
                        obtain.arg1 = cVar.ˎ();
                        handler.sendMessage(obtain);
                    }
                }
            }
        }
    }

    public synchronized void ˎ(Context context) {
        if (!this.ʼ) {
            this.ˏ = context;
            if (VERSION.SDK_INT >= 24) {
                Builder builder = new Builder();
                builder.addCapability(12);
                ((ConnectivityManager) this.ˏ.getApplicationContext().getSystemService(ConnectivityManager.class)).registerNetworkCallback(builder.build(), this.ʽ);
            } else {
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                context.registerReceiver(this.ᐝ, intentFilter);
            }
            this.ʼ = true;
        }
    }

    public void ˋ(Handler handler, int i) {
        synchronized (this.ˎ) {
            this.ˋ.put(handler, Integer.valueOf(i));
        }
    }

    public void ॱ(Handler handler) {
        synchronized (this.ˎ) {
            this.ˋ.remove(handler);
        }
    }
}
